/**
 * Created by zhanglihe on 15/11/7.
 */
require.config(require_config);

define([
    'jquery',
    'common',
    'ready',
    'collection',
    'template',
    'model',
    'dialog',
    'validation',
    'datepicker'
], function ($, common, ready, Collection, template, Model, dialog, Validation) {
    var index = function () {
        this.init();
    };
    index.prototype = {
        init: function () {
            loading();
            this.fetch();
            this.event();
        },

        fetch: function () {
            var _this = this;
            this.collection = new Collection({
                url: _global.url.api + 'self_media/statistics',
                condition: {limit: 20, offset: 0},
                callback: function () {
                    loaded();
                    $('.date-show').html(template('date-show', _this.collection.result.date));
                }
            });
            this.collection.fetch();
        },

        event: function () {
            this.data = {};
            var _this = this;
            //日期
            $('.date').on('click', function () {
                WdatePicker({
                    el: this.id,
                    maxDate: '%y-%M-#{%d-1}',
                    dateFmt: 'yyyy-MM-dd'
                });
            });
            /**
             * 搜索事件
             */
            $('#btn-search').on('click', function (e) {
                e.preventDefault();
                _this.collection.condition.start_time = $('input[name="start_time"]').val();
                _this.collection.condition.end_time = $('input[name="end_time"]').val();
                _this.collection.reload();
            });
        }
    };

    new index();

});